package com.cxm.support.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cxm.support.entity.User;
import com.cxm.support.mapper.UserMapper;
import com.cxm.support.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cxm.support.vo.DataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cxm
 * @since 2022-05-12
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public User findByUsername(String username) {
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);
        return userMapper.selectOne(wrapper);
    }

    @Override
    public DataVO findData(Integer page, Integer limit) {
        DataVO dataVO = new DataVO();
        dataVO.setCode(0);
        dataVO.setMsg("");
        Page<User> page2 = new Page<>(page, limit);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.orderByDesc("id");
        Page<User> page3 = userMapper.selectPage(page2, wrapper);
        dataVO.setCount(page3.getTotal());
        List<User> TypecontentList = page3.getRecords();
        dataVO.setData(TypecontentList);
        return dataVO;
    }


}
